﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.IO;
using System.Security.Cryptography.X509Certificates;
using com.skype.util;

namespace Hugo
{
    class AppKeyPairMgr
    {
        public static String MY_CLASS_TAG = "AppKeyPairMgr";
	    public static String KEY_PAIR_DEFAULT_PATHNAME = "keypair.pem";
        private String pemFilePathname = KEY_PAIR_DEFAULT_PATHNAME;

		public String getPemFilePathname() {
			return (this.pemFilePathname);
		}

        public Boolean isValidCertificate()
        {
            String pathName = getPemFilePathname();
            PemReader myPemReader;
            try
            {
                myPemReader = new PemReader(getPemFilePathname());
                myPemReader.getCertificate();
                myPemReader.getKey();
                return true;
            }
            catch (FileNotFoundException e)
            {
                Console.WriteLine("Could not find certificate at:" + pathName);
                Console.WriteLine(e.Message);
                return (false);
            }
            catch (IOException e)
            {
                Console.WriteLine("Unable to read certificate at:" + pathName);
                Console.WriteLine(e.Message);
                return (false);
            }
            catch (Exception e)
            {
                Console.WriteLine("Certificate file contains invalid certficate data at:" + pathName);
                Console.WriteLine(e.Message);
                return (false);
            }

        }

    }

}